#ifndef __RFIDLIB_AIP_ISO14443A_H__
#define __RFIDLIB_AIP_ISO14443A_H__


#include "rfidlib.h"


#ifdef __cplusplus
extern "C" {
#endif

namespace RFIDLIB
{

RFID_API err_t ISO14443A_ParseTagDataReport(RFID_DN_HANDLE hTagReport, 
										  DWORD *aip_id, 
										  DWORD *tag_id, 
										  DWORD * ant_id, 
										  BYTE uid[], 
										  BYTE *uidlen);
RFID_API RFID_DN_HANDLE ISO14443A_CreateInvenParam(RFID_DN_HANDLE hInvenParamSpecList, 
                                          BYTE AntennaID/* By default set to 0, apply to all antenna */
															);


RFID_API err_t ISO14443A_Connect(RFID_READER_HANDLE hr, BYTE tagType, BYTE uid[], BYTE uidLen, RFID_TAG_HANDLE *ht);



/*
*  ultralight locking block type
*/
enum{
	MFUL_LOCKING_BLK_TYPE_OTP, 
	MFUL_LOCKING_BLK_TYPE_PAGE_4_9, 
	MFUL_LOCKING_BLK_TYPE_PAGE_10_15, 
	MFUL_LOCKING_BLK_TYPE_PAGE_16_27, 
	MFUL_LOCKING_BLK_TYPE_PAGE_28_39, 
	MFUL_LOCKING_BLK_TYPE_PAGE_COUNTER, 
	MFUL_LOCKING_BLK_TYPE_PAGE_AUTH0, 
	MFUL_LOCKING_BLK_TYPE_PAGE_AUTH1, 
	MFUL_LOCKING_BLK_TYPE_PAGE_KEY, 

};

/*
* lock page type
*/
enum{
	MFUL_LOCKING_PAGE_TYPE_PAGE_OTP, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_4, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_5, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_6, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_7, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_8, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_9, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_10, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_11, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_12, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_13, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_14, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_15, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_16_19, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_20_23, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_24_27, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_28_31, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_32_35, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_36_39, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_41, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_42, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_43, 
	MFUL_LOCKING_PAGE_TYPE_PAGE_KEY
};

RFID_API err_t ULTRALIGHT_Connect(RFID_READER_HANDLE hr, BYTE uid[] /* 7 bytes */, RFID_TAG_HANDLE *ht);
RFID_API err_t ULTRALIGHT_LockPage(RFID_READER_HANDLE hr, 
									  RFID_TAG_HANDLE ht, 
									  DWORD pageType); 
RFID_API err_t ULTRALIGHT_LockBlock(RFID_READER_HANDLE hr, 
									   RFID_TAG_HANDLE ht, 
									   DWORD blockType);

RFID_API err_t ULTRALIGHT_ReadMultiplePages(RFID_READER_HANDLE hr, 
											   RFID_TAG_HANDLE ht, 
											   DWORD pageStart, 
											   DWORD pageNum, 
											   BYTE databuf[], 
											   DWORD *nSize );
RFID_API err_t ULTRALIGHT_WriteMultiplePages(RFID_READER_HANDLE hr, 
												RFID_TAG_HANDLE ht, 
												DWORD  pageStart, 
												DWORD pageNum, 
												BYTE databuf[], 
												DWORD bytesToWrite);
RFID_API err_t ULTRALIGHT_Authenticate(RFID_READER_HANDLE hr, 
										  RFID_TAG_HANDLE ht, 
										  BYTE key[] /* 16bytes */);
RFID_API err_t ULTRALIGHT_UpdatePassword(RFID_READER_HANDLE hr, 
											RFID_TAG_HANDLE ht, 
											BYTE key[]);
/*
* auth0:0x03-0x30
* auth1:0:需要认证, 1:不需要认证
*/
RFID_API err_t ULTRALIGHT_UpdateAuthConfig(RFID_READER_HANDLE hr, 
											  RFID_TAG_HANDLE ht, 
											  BYTE auth0, 
											  BYTE auth1);






RFID_API err_t MFCL_Connect(RFID_READER_HANDLE hr, BYTE tagType, BYTE uid[] /* 4 bytes */, RFID_TAG_HANDLE *ht);
RFID_API err_t MFCL_ReadBlock(RFID_READER_HANDLE hr, 
								 RFID_TAG_HANDLE ht, 
								 BYTE  blkAddr, 
								 BYTE  blkData[], 
								 DWORD nSize 
								 );
RFID_API err_t MFCL_ReadMultipleBlocks(RFID_READER_HANDLE hr, 
										  RFID_TAG_HANDLE ht, 
										  BYTE  blkAddr, 
										  BYTE blkNum, 
										  BOOLEAN autoAuth, 
										  BYTE keyType, 
										  BYTE key[], 
										  BYTE  blkData[], 
										  DWORD nSize 
										  );
RFID_API err_t MFCL_WriteMultipleBlocks(RFID_READER_HANDLE hr, 
										   RFID_TAG_HANDLE ht, 
										   BYTE blkAddr, 
										   BYTE blkNum, 
										   BOOLEAN autoAuth, 
										   BYTE keyType, 
										   BYTE key[], 
										   BYTE blkData[], 
										   DWORD nSize );
RFID_API err_t MFCL_WriteBlock(RFID_READER_HANDLE hr, 
								  RFID_TAG_HANDLE ht, 
								  BYTE blkAddr, 
								  BYTE blkData[] /* 16 bytes */);
RFID_API err_t MFCL_Authenticate(RFID_READER_HANDLE hr, 
									RFID_TAG_HANDLE ht, 
									BYTE blkAddr, 
									BYTE keyType, 
									BYTE key[]);
RFID_API err_t MFCL_Increment(RFID_READER_HANDLE hr, 
								 RFID_TAG_HANDLE ht, 
								 BYTE blkAddr, 
								 DWORD val);
RFID_API err_t MFCL_Decrement(RFID_READER_HANDLE hr, 
								 RFID_TAG_HANDLE ht, 
								 BYTE blkAddr, 
								 DWORD val);

RFID_API err_t MFCL_Restore(RFID_READER_HANDLE hr, 
							   RFID_TAG_HANDLE ht, 
							   BYTE blkAddr );

RFID_API err_t MFCL_Transfer(RFID_READER_HANDLE hr, 
								RFID_TAG_HANDLE ht, 
								BYTE blkAddr);

RFID_API err_t MFCL_FormatValueBlock(RFID_READER_HANDLE hr, 
										RFID_TAG_HANDLE ht, 
										BYTE blkAddr, 
										DWORD initValue);
RFID_API err_t MFCL_CreateAccessCondition(BYTE blk0AccType /*in */, 
											 BYTE blk1AccType /*in */, 
											 BYTE blk2AccType /*in */, 
											 BYTE trailerAccType /*in */, 
											 BYTE formattedAccCondi[]/*out */ );
RFID_API BYTE MFCL_Sector2Block(BYTE sector);
RFID_API BYTE MFCL_Block2Sector(BYTE block);
RFID_API BOOLEAN MFCL_IsTailerBlock(BYTE blkAddr);
RFID_API err_t MFCL_ParseAccessCondi(BYTE formattedAccCondi[], BYTE *blk0AccType, BYTE *blk1AccType, BYTE *blk2AccType, BYTE *trailerAccType);


/* 
* NTAG21x functions
*/
RFID_API err_t NTAG21x_Connect(RFID_READER_HANDLE hr, BYTE uid[] /* 7 bytes */, RFID_TAG_HANDLE *ht);
RFID_API err_t NTAG21x_ReadMultiplePages(RFID_READER_HANDLE hr, 
											RFID_TAG_HANDLE ht, 
											DWORD pageStart, 
											DWORD pageNum, 
											BYTE databuf[], 
											DWORD *nSize );
RFID_API err_t NTAG21x_WriteMultiplePages(RFID_READER_HANDLE hr, 
											 RFID_TAG_HANDLE ht, 
											 DWORD pageStart, 
											 DWORD pageNum, 
											 BYTE databuf[], 
											 DWORD bytesToWrite);
RFID_API err_t NTAG21x_Authenticate(RFID_READER_HANDLE hr, 
									   RFID_TAG_HANDLE ht, 
									   DWORD pwd /* in */, 
									   WORD *pack /*out */);
RFID_API err_t NTAG21x_GetVersion(RFID_READER_HANDLE hr, 
									 RFID_TAG_HANDLE ht, 
									 BYTE ver[] /* out */);
RFID_API err_t NTAG21x_ReadCnt(RFID_READER_HANDLE hr, 
								  RFID_TAG_HANDLE ht, 
								  DWORD *counter /* out */);
RFID_API err_t NTAG21x_ReadSig(RFID_READER_HANDLE hr, 
								  RFID_TAG_HANDLE ht, 
								  BYTE sig[] /* out */);




RFID_API err_t ISO14443Ap4_Transceive(RFID_READER_HANDLE hr, 
	RFID_TAG_HANDLE ht, 
	BYTE sndData[], 
	DWORD sndLen, 
	BYTE rcvBuff[], 
	DWORD *nSize /* IN:buffer size, OUT:bytes written */);

/*
* 该API属于 有 连接透传
*/
RFID_API err_t ISO14443Ap3_Transceive(RFID_READER_HANDLE hr, 
	RFID_TAG_HANDLE ht, 

	 BYTE IsTxCRC
	, BYTE IsRxCRC
	, BYTE *reqData
	, DWORD reqLen
	, DWORD nBytesTagWillRet
	, BYTE *pRxBuffer
	, DWORD *nSize
	, DWORD time
	);
/*
* 该API属于 无 连接透传
*/
RFID_API err_t ISO14443Ap3_Transceive_v2(RFID_READER_HANDLE hr, 
	WORD flag
	, BYTE * reqData
	, DWORD reqLen
	, DWORD nBytesTagWillRet
	, BYTE * pRxBuffer
	, DWORD * nSize
	, DWORD time);

}//namespace RFIDLIB

#ifdef __cplusplus
}
#endif

#endif
